import { request } from '@umijs/max';

// 定义接口参数类型
interface ApiParams {
  pageNum?: number;
  pageSize?: number;
  [key: string]: any;
}

interface FileUploadResponse {
  code: number;
  data: string;
  msg?: string;
}

// 获取接口列表
export async function apipage(params: ApiParams) {
  return request('/api/userSystem/institution/selectChildInstitutionList', {
    method: 'GET',
    params,
  });
}

// 新增接口
export async function apiAdd(data: any) {
  return request('/api/userSystem/institution/addInstitutionAndAdmin', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json' // 确保发送JSON格式的数据
    },
    data,
  });
}

// 更新接口
export async function apiUpdate(data: any) {
  return request('/api/userSystem/institution/updateInstitution', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json' // 确保发送JSON格式的数据
    },
    data,
  });
}

// 删除接口
export async function apiDelete(params: ApiParams) {
  return request('/api/userSystem/institution/deleteInstitution', {
    method: 'GET',
    params, // 直接发送params对象，不需要手动字符串化
  });
}

// 获取接口详情
export async function apiDetail(params: ApiParams) {
  return request('/api/userSystem/institution/selectInstitutionAndAdminInfo', {
    method: 'GET',
    params,
  });
}

// 文件上传接口
export async function uploadFile(file: File): Promise<FileUploadResponse> {
  const formData = new FormData();
  formData.append('file', file);

  return request('/api/userSystem/file/uploadUrl', {
    method: 'POST',
    data: formData,
    requestType: 'form',
  });
}
